package com.zjun.core;

import com.zjun.ApplicationContextHolder;
import com.zjun.core.param.IdempotentParamService;
import com.zjun.core.spel.IdempotentSpELByMQExecuteHandler;
import com.zjun.core.spel.IdempotentSpelService;
import com.zjun.core.token.IdempotentTokenService;
import com.zjun.enums.IdempotentSceneEnum;
import com.zjun.enums.IdempotentTypeEnum;

/**
 * 幂等执行处理器工厂
 */
public final class IdempotentExecuteHandlerFactory {
    public static IdempotentExecuteHandler getInstance(IdempotentSceneEnum scent,
                                                              IdempotentTypeEnum type){
        IdempotentExecuteHandler result = null;
        switch (scent){
            case RESTAPI -> {
                switch (type){
                    case PARAM -> result = ApplicationContextHolder.getBean(IdempotentParamService.class);
                    case TOKEN -> result = ApplicationContextHolder.getBean(IdempotentTokenService.class);
                    case SPEL -> result = ApplicationContextHolder.getBean(IdempotentSpelService.class);
                }
            }
            case MQ -> result = ApplicationContextHolder.getBean(IdempotentSpELByMQExecuteHandler.class);
            default -> {
            }
        }
        return result;
    }
}
